// 用户角色枚举
export enum UserRole {
  DETECTIVE = 'DETECTIVE',  // 侦探
  OFFICER = 'OFFICER',      // 警官
  ADMIN = 'ADMIN'           // 管理员
}

// 用户实体类
export class UserModel {
  private id: string;        // 用户ID
  private username: string;  // 用户名
  private realName: string;  // 真实姓名
  private role: UserRole;    // 用户角色
  private email: string;     // 电子邮箱
  private phone: string;     // 电话号码
  private createTime: string; // 创建时间
  
  constructor(
    id: string = '',
    username: string = '',
    realName: string = '',
    role: UserRole = UserRole.OFFICER,
    email: string = '',
    phone: string = '',
    createTime: string = new Date().toISOString()
  ) {
    this.id = id;
    this.username = username;
    this.realName = realName;
    this.role = role;
    this.email = email;
    this.phone = phone;
    this.createTime = createTime;
  }
  
  // Getters
  public getId(): string {
    return this.id;
  }
  
  public getUsername(): string {
    return this.username;
  }
  
  public getRealName(): string {
    return this.realName;
  }
  
  public getRole(): UserRole {
    return this.role;
  }
  
  public getEmail(): string {
    return this.email;
  }
  
  public getPhone(): string {
    return this.phone;
  }
  
  public getCreateTime(): string {
    return this.createTime;
  }
  
  // Setters
  public setId(id: string): void {
    this.id = id;
  }
  
  public setUsername(username: string): void {
    this.username = username;
  }
  
  public setRealName(realName: string): void {
    this.realName = realName;
  }
  
  public setRole(role: UserRole): void {
    this.role = role;
  }
  
  public setEmail(email: string): void {
    this.email = email;
  }
  
  public setPhone(phone: string): void {
    this.phone = phone;
  }
  
  /**
   * 从JSON对象创建UserModel实例
   * @param json JSON对象
   * @returns UserModel实例
   */
  public static fromJson(json: any): UserModel {
    return new UserModel(
      json.id || '',
      json.username || '',
      json.realName || '',
      json.role || UserRole.OFFICER,
      json.email || '',
      json.phone || '',
      json.createTime || new Date().toISOString()
    );
  }
  
  /**
   * 转换为JSON对象
   * @returns JSON对象
   */
  public toJson(): any {
    return {
      id: this.id,
      username: this.username,
      realName: this.realName,
      role: this.role,
      email: this.email,
      phone: this.phone,
      createTime: this.createTime
    };
  }
  
  /**
   * 生成唯一ID
   * @returns 唯一ID字符串
   */
  public static generateId(): string {
    return Date.now().toString() + Math.random().toString(36).substr(2, 9);
  }
}